<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>给指定文件的内容生成散列值</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.hash-equals.html">« hash_equals</a></li>
      <li style="float: right;"><a href="function.hash-final.html">hash_final »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.hash.html">Hash 函数</a></li>
    <li>给指定文件的内容生成散列值</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.hash-file" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">hash_file</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PHP 7, PHP 8, PECL hash &gt;= 1.1)</p><p class="refpurpose"><span class="refname">hash_file</span> &mdash; <span class="dc-title">给指定文件的内容生成散列值</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.hash-file-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>hash_file</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$algo</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$binary</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = []</span></span><br>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>


 </div>

 <div class="refsect1 parameters" id="refsect1-function.hash-file-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">algo</code></dt>

     <dd>

      <p class="para">
       要使用的散列算法的名称（例如：&quot;md5&quot;，&quot;sha256&quot;，&quot;haval160,4&quot; 等）。
       可以在 <span class="function"><a href="function.hash-algos.html" class="function">hash_algos()</a></span> 中查看当前支持的算法。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       要进行散列运算的文件位置的 URL ；支持 fopen 封装协议。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">binary</code></dt>

     <dd>

      <p class="para">
       设置为 <strong><code>true</code></strong> 时，输出原始二进制数据。
       设置为 <strong><code>false</code></strong> 时，输出小写的十六进制字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       各种散列算法的一系列选项数组。目前 MurmurHash 算法仅支持 “seed” 参数。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.hash-file-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">binary</code> 设置为 true， 则返回原始二进制数据表示的信息摘要，
   否则返回十六进制小写字符串格式表示的信息摘要。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.hash-file-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>新增 <code class="parameter">options</code> 参数。</td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.hash-file-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-896">
    <p><strong>示例 #1 <span class="function"><a href="function.hash.html" class="function">hash()</a></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">hash</span><span style="color: #007700">(</span><span style="color: #DD0000">'ripemd160'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;quick&nbsp;brown&nbsp;fox&nbsp;jumped&nbsp;over&nbsp;the&nbsp;lazy&nbsp;dog.'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
ec457d0a974c48d5685a7efa03d137dc8bbde7e3
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.hash-file-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.hash.html" class="function" rel="rdfs-seeAlso">hash()</a> - 生成散列值（消息摘要）</span></li>
    <li class="member"><span class="function"><a href="function.hash-hmac-file.html" class="function" rel="rdfs-seeAlso">hash_hmac_file()</a> - 使用 HMAC 方法和给定文件的内容生成带密钥的散列值</span></li>
    <li class="member"><span class="function"><a href="function.hash-update-file.html" class="function" rel="rdfs-seeAlso">hash_update_file()</a> - 从文件向活跃的散列运算上下文中填充数据</span></li>
    <li class="member"><span class="function"><a href="function.md5-file.html" class="function" rel="rdfs-seeAlso">md5_file()</a> - 计算指定文件的 MD5 散列值</span></li>
    <li class="member"><span class="function"><a href="function.sha1-file.html" class="function" rel="rdfs-seeAlso">sha1_file()</a> - 计算文件的 sha1 散列值</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>